package com.lbd99.data.lbd.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lbd99.data.lbd.service.XContentService;
import com.lbd99.data.lbd.vo.XContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("content")
//@Api(tags = "内容管理", value = "XContentController")
public class XContentController {

    @Autowired
    private XContentService xContentService;

    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    //@ApiOperation(value = "查询列表信息")
    public Map<String, Object> selectList(Integer yearId, int page, int rows, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        //       Map<String,Object> map2=new HashMap<String,Object>();
//        map2.put("phone",request.getParameter("phone"));
        List<XContent> list = xContentService.selectList(yearId);
        int sum = 0;
        for (XContent content : list) {
            int score = 0;
            if (content.getScore() != null) {
                score = content.getScore();
            }
            sum = sum + score;
        }
        XContent xContent = new XContent();
        xContent.setCotent("总分统计：");
        xContent.setScore(sum);

        list.add(xContent);

        PageInfo<XContent> pages = new PageInfo<XContent>(list);
        result.put("total", pages.getTotal());
        result.put("rows", pages.getList());
        return result;
    }

    @RequestMapping(value = "/update")
    //@ApiOperation(value = "修改信息")
    public Map<String, Object> update(XContent bean) {
        return xContentService.updateByPrimaryKeySelective(bean);
    }
}